package com.schillerchina.baselibrary.network.config;

import android.provider.Settings;

import com.schillerchina.baselibrary.network.App;
import com.schillerchina.baselibrary.network.interceptor.LogInterceptor;
import com.schillerchina.baselibrary.network.interceptor.ServerErrorInterceptor;
import com.schillerchina.baselibrary.utils.Pref;

import java.util.Map;

import io.reactivex.ObservableTransformer;
import io.reactivex.functions.Function;
import okhttp3.Interceptor;

/**
 * @author zhangzhiguo
 * @date 2019-08-05 09:39
 * @Description: 服务器网络配置
 */

public class NetConfig {
    private static String DEVICE_ID = Settings.Secure.getString(App.getContext()
            .getContentResolver(), Settings.Secure.ANDROID_ID);
    private static String authorization = Pref.getString("token_type", "") + " " + Pref.getString("Access_token", "");
    //    连接超时时间
    private static int connectionTimeout = 30;
    //    读取超时时间
    private static int readTimeout = 30;
    //    登录类
    private static Class loginClass;
    private static ObservableTransformer transformer;
    private static Function serverErrorInterceptor;
    private static Interceptor interceptor;
    private static Map<String, String> headers;

    static {
        transformer = new ThreadTransformer<>();
        serverErrorInterceptor = new ServerErrorInterceptor<>();
        interceptor = new LogInterceptor();
    }

    public static String getDeviceId() {
        return DEVICE_ID;
    }

    public static void setDeviceId(String deviceId) {
        DEVICE_ID = deviceId;
    }

    public static String getAuthorization() {
        return authorization;
    }

    public static void setAuthorization(String authorization) {
        NetConfig.authorization = authorization;
    }

    public static int getConnectionTimeout() {
        return connectionTimeout;
    }

    public static void setConnectionTimeout(int connectionTimeout) {
        NetConfig.connectionTimeout = connectionTimeout;
    }

    public static int getReadTimeout() {
        return readTimeout;
    }

    public static void setReadTimeout(int readTimeout) {
        NetConfig.readTimeout = readTimeout;
    }

    public static Class getLoginClass() {
        return loginClass;
    }

    public static void setLoginClass(Class loginClass) {
        NetConfig.loginClass = loginClass;
    }

    public static ObservableTransformer getTransformer() {
        return transformer;
    }

    public static void setTransformer(ObservableTransformer transformer) {
        NetConfig.transformer = transformer;
    }

    public static Function getServerErrorInterceptor() {
        return serverErrorInterceptor;
    }

    public static void setServerErrorInterceptor(Function serverErrorInterceptor) {
        NetConfig.serverErrorInterceptor = serverErrorInterceptor;
    }

    public static Interceptor getInterceptor() {
        return interceptor;
    }

    public static void setInterceptor(Interceptor interceptor) {
        NetConfig.interceptor = interceptor;
    }

    public static Map<String, String> getHeaders() {
        return headers;
    }

    public static void setHeaders(Map<String, String> headers) {
        if (NetConfig.headers == null) {
            NetConfig.headers = headers;
        } else {
            NetConfig.headers.putAll(headers);
        }
    }

    public static void resetHeaders() {
        NetConfig.headers.clear();
    }
}
